﻿using System;


namespace myLittleC
{
    class ComException : Exception, IComError
    {
        public ERRORS mErrorCode{get; private set;}
        TPosition mPos;

        
        public ComException(ERRORS iErrorCode) { mErrorCode = iErrorCode;}
        public ComException(ERRORS iErrorCode, TPosition iPos):this(iErrorCode) {   mPos = iPos;}



        public ERRORS ErrorCode { get{ return mErrorCode; }}
        public override String ToString() { return ErrorMessage;}
        public TPosition Position { get { return mPos; } }

        public String ErrorMessage
        {
            get
            {
                String Message = "";
                switch (ErrorCode)
                {
                    case ERRORS.EOF:
                        Message = "Don't find finish of file";
                        break;
                    case ERRORS.UnknownError:
                        Message = "Unknown error";
                        break;
                    case ERRORS.InvalidConstInt:
                        Message = "Bad integer const";
                        break;
                    case ERRORS.InvalidConstFloat:
                        Message = "Bad float const";
                        break;
                    case ERRORS.InvalidConstString:
                        Message = "Bad const String";
                        break;
                    case ERRORS.InvalidEscSeq:
                        Message = "Bad Esc Sting";
                        break;
                    case ERRORS.BadExpression:
                        Message = "Bad Expression";
                        break;
                    case ERRORS.BadUnaryExp:
                        Message = "Bad Unary Expression";
                        break;
                    case ERRORS.ExpRightParan:
                        Message = "Don't find )";
                        break;
                    case ERRORS.BadLValue:
                        Message = "l-value must be variable";
                        break;
                    case ERRORS.BadDeclaration:
                        Message = "Bad Declaration";
                        break;
                    case ERRORS.DublDeclaration:
                        Message = "Item With This Name had Defined";
                        break;
                    case ERRORS.NotDefType:
                        Message = "Don't Define Type";
                        break;
                    case ERRORS.NotUniqDef:
                        Message = "Item With This Name had Defined";
                        break;
                    case ERRORS.ExpSemicolon:
                        Message = "dont find \";\"";
                        break;
                    case ERRORS.NotArraySize:
                        Message = "have not Array Size ";
                        break;
                    case ERRORS.ExpRBreak:
                        Message = "Unexpected \"]\"";
                        break;
                    case ERRORS.CantDefsVar:
                        Message = "Can't Define var";
                        break;
                    case ERRORS.ExpFinBrace:
                        Message = "Unexpected \"}\"";
                        break;
                    case ERRORS.ExpIdent:
                        Message = "Unexpected Identificator";
                        break;
                    case ERRORS.ExpType:
                        Message = "UnIndefened Type";
                        break;
                    case ERRORS.UnIdefSymbol:
                        Message = "UnIndefened Symbol construction";
                        break;
                    case ERRORS.CantDefsFunc:
                        Message = "Can't Define function";
                        break;
                    case ERRORS.CanDefsExpr:
                        Message = "Can't Define Expression";
                        break;
                    case ERRORS.EmpryStruct:
                        Message = "Can't Define Empty Struct";
                        break;
                    case ERRORS.NotUnicDefOrCantDefsFunk:
                        Message = "Item With This Name had Defined or cant Define Funk";
                        break;
                    case ERRORS.ExpDef:
                        Message = "Unknown idendeficator";
                        break;
                    case ERRORS.IncorectType:
                        Message = "Incorrect type in expression";
                        break;
                    case ERRORS.UnKnownOp:
                        Message = "Unknown operation";
                        break;
                    case ERRORS.ExpWhile:
                        Message = "Unexpected \"while\"";
                        break;
                    case ERRORS.NotIdent:
                        Message = "Have not identificator";
                        break;
                    case ERRORS.ExpStartParan:
                        Message = "Unexpected \"(\"";
                        break;
                    case ERRORS.ExpFinishParan:
                        Message = "Unexpected \")\"";
                        break;
                    case ERRORS.ElseBeforeElseIf:
                        Message = "\"else\" before \"else if\"";
                        break;
                    case ERRORS.ElseBeforeIf:
                        Message = "\"else\" before \"if\"";
                        break;
                    case ERRORS.ReturnWithOutFunc:
                        Message = "\"return\" without funkntion";
                        break;
                    case ERRORS.ExpFinishSquareBracket:
                        Message = "Unexpected \"]\"";
                        break;
                    case ERRORS.OutOfFunc:
                        Message = "expr out from funk "; //TODO: проверить правильность
                        break;
                    case ERRORS.ExpRetValue:
                        Message = "funktion not return value ";
                        break;
                    case ERRORS.GlobalVarIsNotConsExpr:
                        Message = "Global Variable is not Cons Expression ";
                        break;
                    case ERRORS.ExpMainFunk:
                        Message = "Unexpected funk \"main\"";
                        break;
                    case ERRORS.CountArgs:
                        Message = "Not Declare func with some args";
                        break;
                    case ERRORS.TypesNotCoincide:
                        Message = "Types Not Coincide";
                        break;
                    default:
                        Message = "Don't define Error";
                        break;
                }
                      
               return String.Format("ERROR: {0}, in {1}", Message, Position);
            }
        }
    }
}
